part of 't3_map_controller.dart';

extension Annotation on T3MapController {
  List<T3Annotation> addAnnotations(List<T3AnnotationOptions> options) {
    final annotations = options.map((e) => T3Annotation(e)).toList();
    final list = annotations.map((e) => e.toJson()).toList();
    _methodChannel.invokeMethod('annotation#add', jsonEncode({
      'annotations' : list
    }));

    _annotations.addAll(annotations);
    return annotations;
  }

  void updateAnnotation({required T3Annotation annotation, required T3AnnotationOptions newOption}) {
    annotation.update(newOption);
    _methodChannel.invokeMethod('annotation#update', jsonEncode(annotation.toJson()));
  }

  void removeAnnotations(List<T3Annotation> annotations) {
    final list = annotations.map((e) => e.toJson()).toList();
    _methodChannel.invokeMethod('annotation#remove', jsonEncode({
        'annotations' : list
    }));

    for (var element in annotations) {
      _annotations.remove(element);
    }
  }

  void showAnnotations({
    required List<T3Annotation> annotations,
    EdgeInsets edgeInsets = EdgeInsets.zero,
    required bool animated,
  }) {
    final list = annotations.map((e) => e.toJson()).toList();
    final json = {
      'annotations' : list,
      "edgeInsets": _edgeInsetsToJson(edgeInsets),
      "animated": animated
    };
    _methodChannel.invokeMethod('annotation#show', jsonEncode(json));
  }
}
